Ext.namespace("GridAdministrative");

GridAdministrative.Info = function() {
	
	//行政ID
	this.administrativeId = new Ext.form.Hidden({
		name :'administrativeId'
	});
	
	//区域片区
	this.cmbArea = new Ext.form.ComboBox({
        width: 150,
        //listWidth : 162,
        fieldLabel: '区域片区',
        name : 'gridId',
        store : new Ext.data.JsonStore({
		   url:"../gridareas/listAllRegionAndDistricts.form",
		   autoLoad : true,
		   root:"districts",
		   fields:["areaId","name"]
		}),
		valueField : 'areaId',
		displayField :'name',
        mode: 'local',
        //typeAhead:true,
        emptyText:'------请选择------',
        triggerAction: 'all',
        selectOnFocus: true
    });
    
    //所在街道/镇
	this.txtTownName = new Ext.form.TextField({
		fieldLabel: '所在街道/镇',
		width: 120
	});
	
	//街道/镇地址
	//路
	//地址-路
	this.txtTownAdress = new Ext.form.Hidden({
		name : 'townAdress'
	});
	this.txtAddressInfoStreet = new Ext.form.TextField({
		fieldLabel : '地址 路',
		name :'addressInfo.street',
		width : 150,
		maxLength : 10
	});
	//弄
	this.txtAddressInfoAlley = new Ext.form.NumberField({
		fieldLabel: '弄',
		name :'addressInfo.alley',
		width: 120,
		maxLength : 10
	});
	//号
	this.txtAddressInfoDoorNum = new Ext.form.NumberField({
		fieldLabel: '号',
		name :'addressInfo.doorNum',
		width: 120,
		maxLength : 10
	});
	
	//街道/镇组织架构（附件）
	this.txtTownOrgStructure = new Ext.form.TextField({
		fieldLabel: '街道/镇组织架构',
		id : 'fileUpload',
		name : 'townOrgStructure',
		inputType: 'file'
	});
	
	//管辖居民户数
	this.txtDenizenNum = new Ext.form.NumberField({
		fieldLabel: '管辖居民户数',
		name :'denizenNum',
		width: 120,
		maxLength : 10
	});
	//管辖常驻人口
	this.txtPermanentPopulation = new Ext.form.NumberField({
		fieldLabel: '管辖常驻人口',
		name :'permanentPopulation',
		width: 120,
		maxLength : 10
	});
	//流动人口
	this.txtFloatingPopulation = new Ext.form.NumberField({
		fieldLabel: '流动人口',
		name :'floatingPopulation',
		width: 120,
		maxLength : 10
	});
	//当地经济规划定位
	this.txtPlanningOrientation = new Ext.form.TextArea({
		fieldLabel : '当地经济规划定位 ',
		width : 430,
		height : 60,
		name : 'planningOrientation',
		maxLength : 4000
	});
	
	//街道/镇联系人
	this.txtTownContract = new Ext.form.Hidden({
		name:'townContractInfo.contactId'
	});	
	this.txtTownContractName = new Ext.form.TextField({
		fieldLabel : '街道/镇联系人',
		name : 'townContactInfo.userName',
		width : 120,
        maxLength : 25
	});	
    this.txtTownContractPhone = new Ext.form.TextField({
		fieldLabel : '街道/镇联系人电话',
		name : 'townContactInfo.phoneNumOffice',
		width : 120,
        maxLength : 15
	});
	
	//街道/镇负责人
	this.txtTownOfficer = new Ext.form.Hidden({
		name:'townOfficer.contactId'
	});	
	this.txtTownOfficerName = new Ext.form.TextField({
		fieldLabel : '街道/镇负责人',
		name : 'townOfficer.userName',
		width : 120,
        maxLength : 25
	});	
    this.txtTownOfficerPhone = new Ext.form.TextField({
		fieldLabel : '街道/镇负责人电话',
		name : 'townOfficer.phoneNumOffice',
		width : 120,
        maxLength : 15
	});
	
	//关键人联系方式
	this.txtKeyContract = new Ext.form.Hidden({
		name:'keyContractInfo.contactId'
	});	
	this.txtKeyContractName = new Ext.form.TextField({
		fieldLabel : '街道/镇联系人',
		name : 'keyContactInfo.userName',
		width : 120,
        maxLength : 25
	});	
    this.txtKeyContractPhone = new Ext.form.TextField({
		fieldLabel : '街道/镇联系人电话',
		name : 'keyContactInfo.phoneNumOffice',
		width : 120,
        maxLength : 15
	});
	
	//基本信息
	this.form = new Ext.form.FormPanel({
		bodyStyle : 'padding: 5px 5px 0',
		frame :true,
		//fileUpload: true, 
		autoScroll : true,
		//autoHeight : true,
		height: 360,
		width : 620,
		labelAlign: 'right',
		labelWidth : 120,
		layout : 'table',
		layoutConfig : {columns:2},
		items:[
			{layout:'form',items:[this.cmbArea]},
            {layout:'form',items:[this.txtTownName]},
			{colspan:2,layout:'form',items:[this.txtAddressInfoStreet]},
            {colspan:2,layout:'form',items:[this.txtAddressInfoAlley]},
            {colspan:2,layout:'form',items:[this.txtAddressInfoDoorNum]},
            {layout:'form', items:[this.txtTownOrgStructure]},
            {layout:'form', items:[this.txtDenizenNum]},
            {layout:'form', items:[this.txtPermanentPopulation]},
            {layout:'form', items:[this.txtFloatingPopulation]},
            {colspan:2,layout:'form', items:[this.txtPlanningOrientation]},
            
            {layout:'form', items:[this.txtTownContractName]},
            {layout:'form', items:[this.txtTownContractPhone]},
            {layout:'form', items:[this.txtTownOfficerName]},
            {layout:'form', items:[this.txtTownOfficerPhone]},
            {layout:'form', items:[this.txtKeyContractName]},
            {layout:'form', items:[this.txtKeyContractPhone]},
            //隐藏字段
            {layout:'form', items:[this.administrativeId,this.txtTownAdress,this.txtTownContract,this.txtTownOfficer,this.txtKeyContract]}  
		]
	});
	
	GridAdministrative.Info.superclass.constructor.call(this, {
		title: '行政信息',
        bodyStyle: 'padding: 5px 5px 0',
        autoHeight: true,
        width: 650,
        resizable: false,
        plain: true,
        modal: true,
        autoScroll: true,
        closeAction: 'hide',
        items: [this.form],
        buttons: [{
            text: '保存',
            cls: 'x-btn-text-icon btn-save',
            handler: this.onSave,
            scope: this
        }, {
            text: '关闭',
            cls: 'x-btn-text-icon btn-cancel',
            handler: this.hide.createDelegate(this, [])
        }]
	});
	
	this.connSave = new Ext.data.Connection({
		url: '../gridareas/saveAdministrative.form?timesnap=' + Date.parse(new Date()),
		method: 'POST'
	});
};

Ext.extend(GridAdministrative.Info, Ext.Window, {
	
	setValues: function(data){
		//console.info(data);
		/*this.txtAreaId.setValue(data.areaId);
		this.txtName.setValue(data.name);
		var type = data.type;
		this.cmbType.setValue(type);
		this.txtDescription.setValue(data.description);
		this.hdGisId.setValue(data.gisId);
		this.selectUserId = data.gridManager;
		this.txtGridManager.setValue(data.gridManagerName);
		this.users.length=0;
		this.users.push({'id':data.gridManager,'name':data.gridManagerName});
		if(type=='1'){
			this.cmbRegion.show();
			this.cmbRegion.getEl().up('.x-form-item').setDisplayed(true);// show label
			this.cmbRegion.setValue(data.rid);
		}else{
			this.cmbRegion.hide();
			this.cmbRegion.getEl().up('.x-form-item').setDisplayed(false); // hide label
		}*/
	},
	onSave: function(btn, event){
		if (!this.form.getForm().isValid()) {
			return;
		}
		Utils.request(this.connSave, {
			params: {
				areaId: this.txtAreaId.getValue(),
				name: this.txtName.getValue(),
				type:this.cmbType.getValue(),
				description: this.txtDescription.getValue(),
				gridManager:this.selectUserId,				
				gisId:this.hdGisId.getValue()
			},
			scope: this,
			success: function(resp, action) {
				this.scope.hide();
			},
			after: function() {}
		});
	}
});

